import { createWebHistory , createRouter } from 'vue-router'
import Project from './components/view/Project.vue';


const routes = [
    {
        path: '/home', //首页
        meta: { title: '计量' },
        component: () => import('@/components/view/Home.vue')
    },
    {
        path: '/', //首页
        meta: { title: '计量' },
        redirect: '/home',
    },
    {
        path: '/service', //服务
        meta: { title: '我们的服务' },
        component: () => import('@/components/view/Service.vue')
    },
    {
        path: '/services/:serv', //我们的服务
        meta: { title: '我们的服务' },
        component: () => import('@/components/view/services.vue'),
        beforeEnter: (to, from,next) => {
            if(!['jhl','hxjl','lxjl','sx','sj','wxd','dc','ylqx','zljs','gljs','qtjs'].includes(to.params.serv)) {
                next('/about');
            }else{
                next();
            }
        }
    },
    {
        path: '/project/:proj', //专项检测
        meta: { title: '专项检测' },
        component: () => import('@/components/view/Project.vue'),
        beforeEnter: (to, from,next) => {
            if(!['aqf','fl','tzsb','rqbjq'].includes(to.params.proj)) {
                next('/about');
            }else{
                next();
            }
        }
    },
    {
        path: '/school/:scl', //专项检测
        meta: { title: '专项检测' },
        component: () => import('@/components/view/School.vue'),
        beforeEnter: (to, from,next) => {
            if(!['jl01','jl02','jl03','jl04','jl05'].includes(to.params.scl)) {
                next('/about');
            }else{
                next();
            }
        }
    },
    {
        path: '/elementor', //标准大全
        meta: { title: '标准大全' },
        component: () => import('@/components/view/Elementor.vue')
    },
    {
        path: '/news', //具体服务
        meta: { title: '新闻中心' },
        component: () => import('@/components/view/News.vue')
    },
    {
        path: '/about', //具体服务
        meta: { title: '联系我们' },
        component: () => import('@/components/view/About.vue')
    },
    {
        path: '/:pathMatch(.*)*', //具体服务
        meta: { title: '联系我们' },
        component: () => import('@/components/view/About.vue')
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

export default router